

getCursorPosition = (e) ->
    if (!e)
      return [0,0];
    if (e.pageX || e.pageY)
      x = e.pageX;
      y = e.pageY;
    else
      x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    # Convert to coordinates relative to the canvas
    x -= screenCanvas.offsetLeft;
    y -= screenCanvas.offsetTop;
    return [x,y];


class MouseFollower
    TileSize: 32
    constructor: (screenCanvas) ->
      This = this
      screenCanvas.addEventListener('mousemove',`function(e){This.onMouseMove(e)}`,true)
      @gameX = @gameY = 0
      @screenX = @screenY = 0
    hasMousePos: (posx,posy) ->
      posx -= @TileSize - mapDis.pixeloffX
      posy -= @TileSize - mapDis.pixeloffY
      @gameY = Math.floor(Math.floor((Math.floor(posx/2)+posy)/@TileSize)+Math.floor((-Math.floor(posx/2)+posy)/@TileSize))
      @gameX = Math.floor(2*Math.floor((Math.floor(posx/2)+posy)/@TileSize)-@gameY)
      @gameY = Math.floor(@gameY/2)
      #@gameY = ((posx//2+posy)//64)+(-posx//2+posy)//64
      #@gameX = (posx//2+posy)//64-@gameY//2
    onMouseMove: (e) ->
      pos = getCursorPosition(e)
      @screenX = pos[0]
      @screenY = pos[1]
      this.hasMousePos(@screenX,@screenY)
      $("#MouseFollower").html(@gameX+":"+@gameY+" "+@screenX+":"+@screenY)